package fr.afcepf.atod19.dreamproject.service.implementation;

import fr.afcepf.atod19.dreamproject.dto.CategorieReveDTO;
import fr.afcepf.atod19.dreamproject.dto.ReveDTO;
import fr.afcepf.atod19.dreamproject.dtoutils.EntityToDTOConverter;
import fr.afcepf.atod19.dreamproject.entity.CategorieReve;
import fr.afcepf.atod19.dreamproject.entity.Reve;
import fr.afcepf.atod19.dreamproject.service.interfaces.IAccueilService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import java.util.List;

@Path("/accueil")
public class AccueilServiceImpl implements IAccueilService {

    private List<Reve> listeRevesPlusVendus;
    private List<Reve> listeNouveauxReves;

    private fr.afcepf.atod19.dreamproject.business.interfaces.IBusinessCatalogue businessCatalogue;

    @Path("/getListeRevesPlusVendus/{categorie}")
    @GET
    @Produces("application/json")
    public List<ReveDTO> getListeRevesPlusVendus(
            @PathParam("categorie") int idCategorieReve) {
        CategorieReve categorieChoisie = businessCatalogue
                .getCategorieReveById(idCategorieReve);
        listeRevesPlusVendus = businessCatalogue
                .getRevesParMeilleuresVentesEtCategorieMere(categorieChoisie, 0, 0);
        return EntityToDTOConverter.getRevesDTO(listeRevesPlusVendus);
    }

    @Path("/getListeNouveauxReves/{categorie}")
    @GET
    @Produces("application/json")
    public List<ReveDTO> getListeNouveauxReves(
            @PathParam("categorie") int idCategorieReve) {
        CategorieReve categorieChoisie = businessCatalogue
                .getCategorieReveById(idCategorieReve);
        listeNouveauxReves = businessCatalogue
                .getNouveauxRevesParCategorieMere(categorieChoisie, 0, 0);
        return EntityToDTOConverter.getRevesDTO(listeNouveauxReves);
    }

    @Path("/getCategoriesRacines")
    @GET
    @Produces("application/json")
    public List<CategorieReveDTO> getCategoriesRacines() {
        List<CategorieReve> categoriesRacines = businessCatalogue.getCategoriesRacines();
        return EntityToDTOConverter.getCategoriesRevesDTO(categoriesRacines);
    }

    public fr.afcepf.atod19.dreamproject.business.interfaces.IBusinessCatalogue getBusinessCatalogue() {
        return businessCatalogue;
    }

    public void setBusinessCatalogue(
            fr.afcepf.atod19.dreamproject.business.interfaces.IBusinessCatalogue businessCatalogue) {
        this.businessCatalogue = businessCatalogue;
    }
}
